package com.atguigu.edu.controller;

import com.atguigu.common.util.R;
import com.atguigu.edu.entity.vo.login.User;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/vue-admin-template")
@CrossOrigin
// @CrossOrigin(origins = {
//         "http://localhost:5500",
//         "http://localhost:9528",
//         "http://127.0.0.1:5500",
//         "http://127.0.0.1:9528",
// })
public class EduLoginController {

    @PostMapping("/user/login")
    public R login(@RequestBody User user) {
        System.out.println(user);
        if ("admin".equals(user.getUsername())) {
            return R.ok().code(20000).data("token", "admin-token");
        } else {
            return R.error().code(40000).message("用户名或密码错误");
        }
    }

    @GetMapping("/user/info")
    public R info(String token) {
        return R.ok()
                .code(20000)
                .data("roles", "[admin]")
                .data("introduction", "I am a super administrator")
                .data("avatar", "https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif")
                .data("name","Super Admin");
    }
}
